﻿using System;
using System.Windows.Forms;
using Attendences.Server.Common;
using System.Xml;
using Attendences.Server.Model;
using System.Linq;

namespace Attendences.Server
{
    public partial class TestForm : Form
    {
        
        public TestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UserDCDataContext wsafDc = new UserDCDataContext();
            Guid uid =  new  Guid( "e852c912-2cbd-403f-a460-ba22b8885602");
            UserView ur = wsafDc.UserViews.SingleOrDefault(l => l.Name == "zhangxiaojing");
            string phone = string.Empty;
            if (ur != null)
            {
                MessageBox.Show(ur.DisplayName);
                  phone = string.Empty;

                  PropertyData pd = wsafDc.PropertyDatas.SingleOrDefault(l => l.NodeID == ur.ID && l.PropertyID == new Guid("f20ed0c3-3d28-42db-b350-a00bc33865f0"));
                if (pd != null)
                    phone = pd.ValueString;

                
            }
            else
            {
                
            }
            MessageBox.Show(phone);
        }

        private string ModuleString(string moduleid)
        {
            return string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?><value type=""System.Guid"">{0}</value>", moduleid);
        }
        private string SendTimeString()
        {
            return string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?><value type=""System.DateTime"">{0}</value>", DateTime.Now);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            msgService.MessagesService ms = new Attendences.Server.msgService.MessagesService();
            string receivers = "<Receivers><Receiver><Name>zhangxiaojing</Name><DisplayName>张晓晶</DisplayName><NodeType>User</NodeType><Email></Email><LCS></LCS><Mobile>13817457808</Mobile><Fax></Fax></Receiver><Receiver><Name>admin</Name><DisplayName>张晓晶</DisplayName><NodeType>User</NodeType><Email></Email><LCS></LCS><Mobile>13764986426</Mobile><Fax></Fax></Receiver></Receivers>";
            string msg = ms.SendMessageByModuleID(ModuleString(Config.DaTingModuleID), "admin", receivers, "爱卿 洗完了嘛？", "爱卿 洗完了嘛？", false, 0, "", SendTimeString());
            Guid id = GetMessageID(msg);
            MessageBox.Show(id.ToString());
        }
        private Guid GetMessageID(string content)
        {
            Guid gd = Guid.Empty;
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(content);
                gd = new Guid(doc.DocumentElement.InnerText);
            }
            catch

            { }

            return gd;


        }

    }
}
